package com.task.core.service.impl;

import java.util.Objects;
import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.task.common.exception.ServiceException;
import com.task.common.utils.SecurityUtils;
import com.task.core.mapper.CheckMapper;
import com.task.core.service.CheckService;

/**
 * @author 迪迦.
 * @date 2024/12/31 16:23
 */
@Service
public class CheckServiceImpl implements CheckService {

  @Resource
  private CheckMapper checkMapper;

  @Override
  public void check(String tableName, String code) {
    if (SecurityUtils.isAdmin() || SecurityUtils.isSecondAdmin()) {
      return;
    }
    if (!Objects.equals(SecurityUtils.getUserId(), checkMapper.getCreateUser(tableName, code))) {
      throw new ServiceException("非管理员不能操作他人数据");
    }
  }
}
